const fp = require('lodash/fp')
var { cars } = require('./data.js')

//练习1
const f1 = fp.flowRight(fp.prop('in_stock'), fp.last)
console.log(f1(cars))

//练习2
const f2 = fp.flowRight(fp.prop('name'), fp.first)
console.log(f2(cars))

//练习3（不会）
let _average = function (xs) {
  console.log(xs)
  return fp.reduce(fp.add, 0, xs) / xs.length
}
const averageDollarValue = fp.flowRight(_average(), fp.map(car => {
  return car.dollar_value
}))
console.log(averageDollarValue(cars))

//练习4
const sanitizeNames = fp.flowRight(fp.replace(' ', '_'), fp.lowerCase)
console.log(sanitizeNames(["Hello World"]))